import 'package:flutter/material.dart';
import 'package:flutter_demo/ui/pages/status/data/share_data.dart';
import 'package:flutter_demo/ui/pages/status/provider/future/a2_page_widget.dart';
import 'package:flutter_demo/ui/pages/status/provider/future/b2_page_widget.dart';
import 'package:provider/provider.dart';

//参考文档 https://blog.csdn.net/Lastdoggod/article/details/125955791
class FutureProviderTestWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _FutureProviderTestState();
}

class _FutureProviderTestState extends State<FutureProviderTestWidget> {
  @override
  Widget build(BuildContext context) {
    /**
     * 所以我们也可以看到，FutureProvider没有Listenable()，那可想而知，
     * FutureProvider并没有监听模型的功能，只能通过Create创建的Future函数去改变值。
     * 此处使用 ShareDataNotifier 或 ShareData 结果是一样的，都是无法刷新页面
     */
    return FutureProvider<ShareData>(
      //初始数据
      initialData: ShareData(nickname: "正在初始化 ...", level: 0),
      //初始话完成数据
      create: (context) {
        return Future.delayed(const Duration(seconds: 2), () {
          return ShareData(nickname: "tc ...", level: 0);
        });
      },
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: const [A2PageWidget(), B2PageWidget()],
      ),
    );
  }
}
